{% extends 'ne.jinja2' %}
{% block query %}
SELECT

  gid AS __id__,

  {% filter geometry %}the_geom{% endfilter %} AS __geometry__,
  NULL::bytea AS __label__,

  {{ ne_common_properties() }},

  NULL::jsonb AS __boundaries_properties__,
  NULL::jsonb AS __earth_properties__,
  NULL::jsonb AS __landuse_properties__,

  jsonb_build_object(
    'name', name,
    {%- for lang in ne_languages %}
    'name_{{lang}}', name_{{lang}},
    {%- endfor %}
    'population', pop_max,
    'featurecla', featurecla,
    'scalerank', scalerank,
    'min_zoom', mz_places_min_zoom,
    'wikidata', wikidataid
  ) || jsonb_build_object(
{#- need to have a separate call to jsonb_build_object for viewpoints because it doesn't support more than 100 parameters, and we're over that with the number of languages + number of viewpoints #}
{%- for vpt in ne_viewpoints %}
    'fclass_{{vpt}}', fclass_{{vpt}}{{ "," if not loop.last }}
{%- endfor %}
  ) AS __places_properties__,

  NULL::jsonb AS __roads_properties__,
  NULL::jsonb AS __water_properties__

FROM ne_10m_populated_places

WHERE

  {{ bounds['point']|bbox_filter('the_geom', 3857) }} AND
  mz_places_min_zoom < {{ zoom + 1 }}
{% if zoom >= 8 and zoom < 10 %}
  AND pop_max <= 50000
{% elif zoom >= 10 and zoom < 11 %}
  AND pop_max <= 20000
{% elif zoom >= 11 %}
  AND pop_max <= 5000
{% endif %}

{% endblock %}
